// loading.directive.js
import { Spin } from "ant-design-vue";

export const vLoading = {
  mounted(el, binding) {
    if (binding.value) {
      const spin = Spin.open({
        ...binding.value,
        body: el,
      });
      el._spin = spin;
    }
  },
  updated(el, binding) {
    if (binding.value) {
      el._spin.update({
        ...binding.value,
        body: el,
      });
    } else {
      Spin.remove();
    }
  },
  unmounted(el) {
    if (el._spin) {
      Spin.remove();
    }
  },
};
